package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.domain.dao.WarehouseUserDao;
import com.xbongbong.saas.domain.entity.UserAndDepTeamEntity;
import com.xbongbong.saas.domain.entity.WarehouseUserEntity;
import com.xbongbong.saas.model.WarehouseUserModel;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/2/16 21:31
 * @since v1.0
 */
@Service("warehouseUserModel")
public class WarehouseUserModelImpl implements WarehouseUserModel {

    @Resource
    private WarehouseUserDao warehouseUserDao;

    /**
     * 插入数据
     *
     * @param warehouseUserEntity 仓库团队实体数据
     * @author feng.zheng
     * @date 2019/2/15 20:00
     * @since v1.0
     **/
    @Override
    public Integer insert(WarehouseUserEntity warehouseUserEntity) {
        return warehouseUserDao.insert(warehouseUserEntity);
    }

    /**
     * 更新数据
     *
     * @param warehouseUserEntity 仓库团队实体数据
     * @author feng.zheng
     * @date 2019/2/15 20:00
     * @since v1.0
     **/
    @Override
    public Integer update(WarehouseUserEntity warehouseUserEntity) {
        return warehouseUserDao.update(warehouseUserEntity);
    }

    /**
     * 根据id查询数据
     *
     * @param key    主键
     * @param corpid 公司ID
     * @author feng.zheng
     * @date 2019/2/15 20:00
     * @since v1.0
     **/
    @Override
    public WarehouseUserEntity getByKey(Long key, String corpid) {
        return warehouseUserDao.getByKey(key, corpid);
    }

    /**
     * 根据参数查询盘点单实体集合
     *
     * @param param 查询条件
     * @return java.util.List<com.xbongbong.saas.domain.entity.ext.WarehouseEntityExt>
     * @author feng.zheng
     * @date 2019/2/15 14:45
     */
    @Override
    public List<WarehouseUserEntity> findEntitys(Map<String, Object> param) {
        return warehouseUserDao.findEntitys(param);
    }

    /**
     * 根据主键删除记录
     *
     * @param key    主键
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author feng.zheng
     * @date 2019/2/16 21:16
     */
    @Override
    public Integer deleteByKey(Long key, String corpid) {
        return warehouseUserDao.deleteByKey(key, corpid);
    }

    /**
     * 根据参数获取实体集合数目
     *
     * @param param 参数
     * @return java.lang.Integer
     * @author feng.zheng
     * @date 2019/2/16 21:13
     */
    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return warehouseUserDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    /**
     * 根据relationId和type删除记录
     *
     * @param corpid      公司id
     * @param warehouseId 仓库id
     * @param userIdIn    员工id
     * @param type        类型
     * @return java.lang.Integer
     * @author feng.zheng
     * @date 2019/2/18 10:09
     */
    @Override
    public Integer deleteByUserIdIn(String corpid, Long warehouseId, List<String> userIdIn, Integer type) {
        return warehouseUserDao.deleteByUserIdIn(corpid, warehouseId, userIdIn, type);
    }

    /**
     * 根据relationId和type删除记录
     *
     * @param corpid      公司id
     * @param warehouseId 仓库id
     * @param depIdIn     部门id
     * @param type        类型
     * @return java.lang.Integer
     * @author feng.zheng
     * @date 2019/2/18 10:09
     */
    @Override
    public Integer deleteByDepIdIn(String corpid, Long warehouseId, List<Long> depIdIn, Integer type) {
        return warehouseUserDao.deleteByDepIdIn(corpid, warehouseId, depIdIn, type);
    }

    @Override
    public List<UserAndDepTeamEntity> findBaseEntitys(Map<String, Object> map) {
        return warehouseUserDao.findBaseEntitys(map);
    }

    @Override
    public List<WarehouseUserEntity> getUserListByDataId(String corpid, Long id) {
        return warehouseUserDao.getUserListByDataId(corpid, id);
    }

    @Override
    public void deleteBatchByIds(String corpid, List<Long> ids, Integer del) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        warehouseUserDao.deleteBatchByIds(corpid, ids, del);
    }

    @Override
    public void updateBatch(List<WarehouseUserEntity> warehouseUserEntities, String corpid) {
        if (CollectionUtils.isEmpty(warehouseUserEntities)) {
            return;
        }
        warehouseUserDao.updateBatch(warehouseUserEntities, corpid);
    }

    @Override
    public void deleteByDataIds(List<Long> dataIds, String corpid) {
        warehouseUserDao.deleteByDataIds(dataIds, corpid);
    }

    @Override
    public void  batchUpdateByUserIdIn(String corpid, List<Long> idIn,Integer del) {
        warehouseUserDao.batchUpdateByIdIn(corpid,idIn,del);
    }

    @Override
    public List<WarehouseUserEntity> getUserListByTypeAndDataIdIn(String corpid, Integer type,List<Long> dataIdIn,List<String> userIdIn) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid",corpid);
        param.put(StringConstant.DEL,BasicConstant.ZERO);
        param.put("type",type);
        param.put("dataIdIn",dataIdIn);
        param.put("relationIdIn",userIdIn);
        return findEntitys(param);
    }

    @Override
    public Integer insertBatch(List<WarehouseUserEntity> list, boolean isImport) {
        return warehouseUserDao.insertBatch(list);
    }
}
